/*
 *  功能描述   : 串口接收协议
 *  说明: 接收RX数据，通过协议解析，实现改变PID等功能
 *  ----------------------------------------------------------------
 *  ----------------------------------------------------------------
 */

#ifndef __SERIAL_RX_H
#define __SERIAL_RX_H

#define FRAME_HEAD 0xfc
#define FRAME_END 0xfd
#define TYPE_IMU 0x40
#define TYPE_AHRS 0x41
#define TYPE_INSGPS 0x42
#define TYPE_GROUND 0xf0
#define IMU_LEN  0x38   //56+8  8组数据
#define AHRS_LEN 0x30   //48+8  7组数据
#define INSGPS_LEN 0x42 //72+8  10组数据
#define IMU_CAN 9
#define AHRS_CAN 8
#define INSGPS_CAN 11
#define IMU_RS 64
#define AHRS_RS 56


#include "system.h"
#include "stm32f10x.h"
#include "string.h"

void UART1_Receive(uint8_t RXBUF);
void UART2_Receive(uint8_t RXBUF);
int UARTData_Process(uint8_t *UART_RX_BUF,uint16_t UART_STA);

float CharToNum(uint8_t *cData,uint8_t len);
int DataS_Process(uint8_t *UART_RX_BUF,uint16_t UART_STA);

void CopeSerial2Data(unsigned char ucData);

void N100_Receive(u8 Usart_Receive);
u8 TTL_Hex2Dec(void);  
float DATA_Trans(u8 Data_1,u8 Data_2,u8 Data_3,u8 Data_4);
long long timestamp(u8 Data_1,u8 Data_2,u8 Data_3,u8 Data_4);

struct SAcc
{
	short a[3];
	short T;
};
struct SGyro
{
	short w[3];
	short T;
};
struct SAngle
{
	short Angle[3];
	short T;
};
extern struct SAcc 		stcAcc;
extern struct SGyro 		stcGyro;
extern struct SAngle 	stcAngle;
extern struct IMUData_Packet_t IMUData_Packet;
extern struct AHRSData_Packet_t AHRSData_Packet;
typedef struct IMUData_Packet_t{
		float gyroscope_x;          //unit: rad/s
		float gyroscope_y;          //unit: rad/s
		float gyroscope_z;          //unit: rad/s
		float accelerometer_x;      //m/s^2
		float accelerometer_y;      //m/s^2
		float accelerometer_z;      //m/s^2
		float magnetometer_x;       //mG
		float magnetometer_y;       //mG
		float magnetometer_z;       //mG
		float imu_temperature;      //C
		float Pressure;             //Pa
		float pressure_temperature; //C
		u32 Timestamp;          //us
} IMUData_Packet_t;

typedef struct AHRSData_Packet_t
{
	float RollSpeed;   //unit: rad/s
	float PitchSpeed;  //unit: rad/s
	float HeadingSpeed;//unit: rad/s
	float Roll;        //unit: rad
	float Pitch;       //unit: rad
	float Heading;     //unit: rad
	float Qw;//w          //Quaternion
	float Qx;//x
	float Qy;//y
	float Qz;//z
	u32 Timestamp; //unit: us
}AHRSData_Packet_t;
#endif  
	 



